using System;
using System.Collections.Generic;
using System.Text; 
using System.Security.Cryptography;
using System.IO;

namespace Kcitwm.Utilities
{
    public class DESEncrypt
    {
        private static readonly byte[] IV = { 0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01 }; 
        public static string Encrypt(string data, string key)
        {
            Encoding enc = Encoding.UTF8;
            System.Security.Cryptography.DES des = System.Security.Cryptography.DES.Create();
            int size = data.Length;
            byte[] result = des.CreateEncryptor(enc.GetBytes(key), IV).TransformFinalBlock(enc.GetBytes(data), 0, size);
            des.Clear();
            return Convert.ToBase64String(result);
        }

        public static string Decrypt(string data, string key)
        {
            Encoding enc = Encoding.UTF8;
            byte[] source = Convert.FromBase64String(data);
            System.Security.Cryptography.DES des = System.Security.Cryptography.DES.Create();
            int size = source.Length;
            byte[] result = des.CreateDecryptor(enc.GetBytes(key), IV).TransformFinalBlock(source, 0, size);
            des.Clear();
            return enc.GetString(result);
        } 
        

    }
}
